package com.wf.service.impl;

import com.wf.client.GoodsClient;
import com.wf.mapper.OrderMapper;
import com.wf.pojo.Goods;
import com.wf.pojo.Order;
import com.wf.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    OrderMapper orderMapper;

//    @Autowired
//    RestTemplate restTemplate;
    @Autowired
    GoodsClient goodsClient;

    public Order getById(Long orderID) {
        //查询订单
        Order order = orderMapper.selectById(orderID);
        //远程调用goods
        Goods goods = goodsClient.getById(order.getGoodsId());
        order.setGoods(goods);
        return order;
    }

    /**
     * 新增订单
     * @param goodsId
     */
    @Override
    public void insert(Long goodsId) {
        //获取商品信息
        Goods goods = goodsClient.getById(goodsId);
        //商品库存-1
        goods.setNum(goods.getNum()-1);
//        //商品库存-1
//        goodsClient.update(goods);
        //新增订单信息
        Order order = new Order();
        order.setId(2L);
        order.setGoodsId(goodsId);
        order.setNum(2);
        order.setName("订单二");
        order.setPrice(222.0);
        order.setOrderId(2L);
        orderMapper.insert(order);

    }
}
